﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Form12
{
    public partial class Form3 : Form
    {
        public int t;
        public Form3()
        {
            InitializeComponent();
        }

        public string GetTimeFormat(int t)
        {
            string hh, mm, ss, mms;
            int temp = t / 100;//获取以秒为单位的总秒数
            int h = temp / 3600;
            int m = temp / 60 % 60;
            int s = temp % 60;
            int ms = t % 100;
            if (h < 10) hh = "0" + h.ToString();
            else hh = h.ToString();
            if (m < 10) mm = "0" + m.ToString();
            else mm = m.ToString();
            if (s < 10) ss = "0" + s.ToString();
            else ss = s.ToString();
            if (ms < 10) mms = "0" + ms.ToString();
            else mms = ms.ToString();
            return hh + ":" + mm + ":" + ss + "." + mms;

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            t++;
            label1.Text = GetTimeFormat(t);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (timer1.Enabled == true)    //如果正在工作
            {
                timer1.Stop();             //将其停止
                button1.Text = "开始计时";
                button2.Enabled = true;    //显示button2按钮
            }
            else
            {
                timer1.Start();
                button1.Text = "暂停";
               button2.Enabled = false;   
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label1.Text = GetTimeFormat(0);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
